﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using F_MODEL;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace F_DAL
{
    public class StaffLogin
    {
        string str = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="staffNum"></param>
        /// <param name="staffpwd"></param>
        /// <returns></returns>
        public int LoginStaffDo(string staffNum, string staffpwd)
        {

            using (SqlConnection conn = new SqlConnection(str))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = @"select count(*) from staffinfo where staffNum =@staffNum and password=@staffpwd";
                    cmd.Parameters.Add("@staffNum", staffNum);
                    cmd.Parameters.Add("@staffpwd", staffpwd);
                    int i = Convert.ToInt32(cmd.ExecuteScalar());
                    return i;

                }

            }

        }
        /// <summary>
        /// 工作人员信息
        /// </summary>
        /// <param name="staffNum"></param>
        /// <returns></returns>
        public List<StaffInfo> getlist(string staffNum)
        {
            using (SqlConnection conn = new SqlConnection(str))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = @"select A.*,B.stationName from StaffInfo A  inner join TransferStation B on A.stationId=B.stationId where staffNum =@staffNum";
                    cmd.Parameters.Add("@staffNum", staffNum);
                    List<StaffInfo> list = new List<StaffInfo>();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        list.Add(new StaffInfo()
                        {
                            staffId = Convert.ToInt32(reader["staffId"]),
                            staffNum = reader["staffNum"].ToString(),
                            staffName = reader["staffName"].ToString(),
                            stationId = Convert.ToInt32(reader["stationId"]),
                            password = reader["password"].ToString(),
                            staffIsDel = Convert.ToInt32(reader["staffIsDel"]),
                            stafftimeSpan = reader["stafftimeSpan"].ToString(),
                            stationName = reader["stationName"].ToString()
                        });

                    }

                    return list;

                }
            }
        }
        /// <summary>
        /// 查询中转地址
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        public string addr(int sid)
        {
            using (SqlConnection conn = new SqlConnection(str))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = @"select stationName from  dbo.TransferStation where [stationId]=@stationId";
                    cmd.Parameters.Add("@stationId", sid);

                    string i = cmd.ExecuteScalar().ToString();
                    return i;

                }

            }
        }


    }
}
